/*
 * @Author: xiaoyangzhao
 * @Date:   2018-08-06 14:21:57
 * @Last Modified by:   xiaoyangzhao
 * @Last Modified time: 2019-08-06 16:29:29
 */

import request from '@/utils/request'
import { route_origins, route_path_get } from '@/api/routes'
// import { callLogOut } from '@/api/call'
// import * as callSocket from '@/views/taskList/callDeskTop'

/**
 * [overdueLogin 登录携带ic和ui]
 * @param  {String} username  [用户名称]
 * @param  {String} password  [密码]
 * @param  {String} imageCode [图形验证码]
 * @return {Function}         [异步接口方法]
 */
export const overdueLogin = (params: any) =>
  request({
    url: route_origins + route_path_get + 'validateLogin',
    method: 'get',
    params
  })

/**
 * [login 登录]
 * @param  {String} username  [用户名称]
 * @param  {String} password  [密码]
 * @param  {String} imageCode [图形验证码]
 * @return {Function}         [异步接口方法]
 */
export const login = (params: any) => {
  // callLogOut()
  const { username, password, imageCode } = params
  request({
    // url: route_origins + route_path_get + 'login',
    url: route_origins + route_path_get + 'login',
    method: 'post',
    // timeout: 1e3 * 60 * 30,
    data: {
      username: username,
      password: password,
      imageCode: imageCode,
      ajax: 'XMLHttpRequest'
    }
  })
}

/**
 * [imgCaptcha 图形验证码]
 * @param  {Object} params    [description]
 * @return {Function}         [异步接口方法]
 */
export const imgCaptcha = (params: any) => {
  request({
    // url: 'http://echo-star-dev4.zhichengcredit.com/jcaptcha?' + Date.now(),
    url: route_origins + route_path_get + 'jcaptcha?' + Date.now(),
    method: 'get',
    responseType: 'stream',
    params
  })
}

/**
 * [getInfo 获取用户信息]
 * @param  {Array} token  [用户角色口令]
 * @return {Function}     [异步接口方法]
 */
export const getInfo = (token: any) => {
  return request({
    url: route_origins + route_path_get + 'user/info',
    method: 'get',
    params: {
      token,
      ajax: 'XMLHttpRequest'
    }
  })
}

/**
 * [logout 登出]
 * @return {Function}     [异步接口方法]
 */
export const logout = () => {
  return request({
    url: route_origins + route_path_get + 'logout',
    method: 'get'
  })
}

/**
 * [userModifyPwd 重置密码]
 * @param  {Object} params [旧密码oldPassword/新密码newPassword]
 * @return {Function}      [异步接口方法]
 */
export const userModifyPwd = (params: any) => {
  return request({
    url: route_origins + route_path_get + 'user/modifyPwd',
    method: 'post',
    params
  })
}

/**
 * [userResetPwd 重置密码]
 * @param  {Object} params [旧密码oldpassword/新密码newpassword]
 * @return {Function}      [异步接口方法]
 */
export const userResetPwd = (params: any) => {
  return request({
    url: route_origins + route_path_get + 'user/resetPwd',
    method: 'post',
    params
  })
}

/**
 * [userTodo 首页 待办事项]
 * @return {Function}     [异步接口方法]
 */
export const userTodo = (params: any) => {
  return request({
    url: route_origins + route_path_get + 'user/todo',
    method: 'get',
    params
  })
}

/**
 * [reportCoverHome 首页 覆盖率报表数据]
 * @return {Function}     [异步接口方法]
 */
export const reportCoverHome = (params: any) => {
  return request({
    url: route_origins + route_path_get + 'report/cover/query/home',
    method: 'get',
    params
  })
}

/**
 * [reportAvgEfficiencyHome 首页 首页平均处理时效数据]
 * @return {Function}     [异步接口方法]
 */
export const reportAvgEfficiencyHome = (params: any) => {
  return request({
    url: route_origins + route_path_get + 'report/avg_efficiency/query/home',
    method: 'get',
    params
  })
}
